package com.林子祺.CAT旅游系统.dao.login;

import com.林子祺.CAT旅游系统.entity.login.RegisterStatus;

import java.sql.*;

public class RegisterAccount {

    public static void addAccount(String name, String password) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        String n = name;
        String p = password;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelsys", "root", "@Blink102417");

            String sql = "insert into user values(null,"+"'"+name+"','"+password+"',0,0)";

            stmt = conn.createStatement();

            stmt.execute(sql);

            RegisterStatus.reg = true;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            if(rs != null) {
                try {
                    rs.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(conn != null) {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }
}
